Avoid mime sniffing where possible
authorMatthias Clasen <mclasen@redhat.com>
Sat, 8 Feb 2020 15:22:54 +0000 (10:22 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 8 Feb 2020 15:22:54 +0000 (10:22 -0500)
When we are loading symbolic pngs or svgs, we know
that we need to the png or svg loader, so there is
no need to go through (surprisingly expensive) mime
sniffing to find the right loader.

gtk/gdkpixbufutilsprivate.h
gtk/gtkcssimagerecolor.c
gtk/tools/gdkpixbufutils.c

index d68d315df7f51d1fa4c882aa1194d994bfb44c3b..73e1c79e96f777be07095da639dcffef081d3ba1 100644 (file)
@@ -79,11 +79,13 @@ GdkPixbuf *gtk_make_symbolic_pixbuf_from_resource (const char    *path,
                                                    int            height,
                                                    double         scale,
                                                    GError       **error);
+GdkTexture *gtk_load_symbolic_texture_from_file     (GFile         *file);
 GdkTexture *gtk_make_symbolic_texture_from_file     (GFile         *file,
                                                      int            width,
                                                      int            height,
                                                      double         scale,
                                                      GError       **error);
+GdkTexture *gtk_load_symbolic_texture_from_resource (const char    *data);
 GdkTexture *gtk_make_symbolic_texture_from_resource (const char    *path,
                                                      int            width,
                                                      int            height,
index 78f91d9f53a8f150b28e12dc3c2d36a5355379a5..23cbb16bbe2e07b993bd2d08e73112aad8aad595 100644 (file)
@@ -109,7 +109,7 @@ gtk_css_image_recolor_load_texture (GtkCssImageRecolor  *recolor,
       char *resource_path = g_uri_unescape_string (uri + strlen ("resource://"), NULL);
 
       if (g_str_has_suffix (uri, ".symbolic.png"))
-        recolor->texture = gdk_texture_new_from_resource (resource_path);
+        recolor->texture = gtk_load_symbolic_texture_from_resource (resource_path);
       else
         recolor->texture = gtk_make_symbolic_texture_from_resource (resource_path, 0, 0, 1.0, NULL);
 
@@ -118,7 +118,7 @@ gtk_css_image_recolor_load_texture (GtkCssImageRecolor  *recolor,
   else
     {
       if (g_str_has_suffix (uri, ".symbolic.png"))
-        recolor->texture = gdk_texture_new_from_file (recolor->file, NULL);
+        recolor->texture = gtk_load_symbolic_texture_from_file (recolor->file);
       else
         recolor->texture = gtk_make_symbolic_texture_from_file (recolor->file, 0, 0, 1.0, NULL);
     }
index c706d720a85d194cc9adc44b5987c2855aab7b4d..1bbde140ba7e55ceda501534506f5e4c6e16db9d 100644 (file)
@@ -560,6 +560,19 @@ gtk_make_symbolic_pixbuf_from_file (GFile       *file,
   return pixbuf;
 }
 
+GdkTexture *
+gtk_load_symbolic_texture_from_resource (const char *path)
+{
+  GdkPixbuf *pixbuf;
+  GdkTexture *texture;
+
+  pixbuf = _gdk_pixbuf_new_from_resource (path, "png", NULL);
+  texture = gdk_texture_new_for_pixbuf (pixbuf);
+  g_object_unref (pixbuf);
+
+  return texture;
+}
+
 GdkTexture *
 gtk_make_symbolic_texture_from_resource (const char  *path,
                                          int          width,
@@ -580,6 +593,28 @@ gtk_make_symbolic_texture_from_resource (const char  *path,
   return texture;
 }
 
+GdkTexture *
+gtk_load_symbolic_texture_from_file (GFile *file)
+{
+  GdkPixbuf *pixbuf;
+  GdkTexture *texture;
+  GInputStream *stream;
+
+  stream = G_INPUT_STREAM (g_file_read (file, NULL, NULL));
+  if (stream == NULL)
+    return NULL;
+
+  pixbuf = _gdk_pixbuf_new_from_stream (stream, "png", NULL, NULL);
+  g_object_unref (stream);
+  if (pixbuf == NULL)
+    return NULL;
+
+  texture = gdk_texture_new_for_pixbuf (pixbuf);
+  g_object_unref (pixbuf);
+
+  return texture;
+}
+
 GdkTexture *
 gtk_make_symbolic_texture_from_file (GFile       *file,
                                      int          width,